package com.marktotop.controller.business;

import com.marktotop.entity.business.VaccinationRecord;
import com.marktotop.error.SystemException;
import com.marktotop.response.ResultBean;
import com.marktotop.service.IReservationRecordService;
import com.marktotop.service.IVaccinationRecordService;
import com.marktotop.vo.business.InoculateVO;
import com.marktotop.vo.business.ReservationRecordVO;
import com.marktotop.vo.business.SiteReservationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * <p>
 *  前端控制器 - 疫苗接种记录
 * </p>
 *
 * @author MarkToTop
 * @since 2021-07-12
 */
@Api(tags = "业务模块-接种疫苗接口")
@RestController
@RequestMapping("/business/inoculate")
public class VaccinationRecordController {

    @Autowired
    private IReservationRecordService reservationService;

    @Autowired
    private IVaccinationRecordService vaccinationRecordService;


    /**
     * 查询出所有已经受理的预约申请
     *
     * @param pageNum
     * @param pageSize
     * @param reservationRecordVO
     * @return
     * @throws ParseException
     */
    @ApiOperation(value = "预约受理记录", notes = "查询出所有已经受理的预约申请")
    @RequestMapping(value = "/findCaseList",method = RequestMethod.GET)
    @RequiresPermissions({"inoculate:show"})
    public ResultBean getAllCaseList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize") Integer pageSize,
                                     ReservationRecordVO reservationRecordVO) throws ParseException {
        reservationRecordVO.setStates(1);
        return reservationService.findReservationRecordsList(pageNum,pageSize,reservationRecordVO);
    }


    /**
     * 获取单个受理的接种信息
     *
     * @param id
     * @return
     * @throws SystemException
     */
    @ApiOperation(value = "获取单个接种信息", notes = "获取单个接种所需要信息")
    @RequestMapping(value = "/get/{id}",method = RequestMethod.GET)
    @RequiresPermissions({"inoculate:edit"})
    public ResultBean getOneInoculateRecord(@PathVariable Long id) throws SystemException {
        InoculateVO oneRecord = vaccinationRecordService.getOneInoculateRecord(id);
        if(oneRecord == null){
            return ResultBean.error().message("查询接种信息失败！");
        }
        return ResultBean.ok().data("result",oneRecord).message("查询接种信息成功！");
    }


    /**
     * 对已经受理的预约人进行接种
     *
     * @param vaccinationRecord
     * @return
     */
    @ApiOperation(value = "提交接种记录", notes = "对已经受理的预约人进行接种")
    @RequestMapping(value = "/postForm",method = RequestMethod.POST)
    @RequiresPermissions({"inoculate:add"})
    public ResultBean inoculateVaccine(@RequestBody VaccinationRecord vaccinationRecord) throws SystemException {
        System.out.println(vaccinationRecord);
        if (!vaccinationRecordService.postInoculateVaccine(vaccinationRecord)){
            return ResultBean.error().message("接种信息添加失败，未完成接种记录!");
        }
        return ResultBean.ok().message("接种信息已经添加成功,已完成接种,等待留观!");
    }


    /**
     * 根据接种点id查找该接种点所有的疫苗预约信息
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "某接种点所有预约记录", notes = "根据接种点id查找该接种点所有的疫苗预约信息")
    @RequestMapping(value = "/findCaseById/{id}",method = RequestMethod.GET)
    public ResultBean getInoculateRecordBySite(@PathVariable Long id){
        SiteReservationVO recordsBySite = reservationService.getRecordsBySite(id);
        return ResultBean.ok().data("result",recordsBySite);
    }


}
